<template>
    <div>
        <el-form ref="form" :model="form" label-width="140px">
            <div class="box5">
                <el-form-item label="来源类型:" required>
                    <el-select v-model="basicForm.sourceType_" placeholder="请选择" size="mini" disabled>
                        <el-option v-for="(value, key) in Dict.sourceTypePojo" :value="key" :key="key" :label="value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="来源分组:" required>
                    <el-select v-model="basicForm.sourceGroupType_" placeholder="请选择" size="mini" disabled>
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
            </div>
            <div class="source">
                <h3>来源信息</h3>
                <div class="form-box">
                    <div class="box1">
                        <el-form-item label="来源名称:" required>
                            <el-input v-model="basicForm.sourceName_" size="mini" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="来源版本号:" required>
                            <el-input v-model="basicForm.sourceVersion_" size="mini" disabled></el-input>
                        </el-form-item>
                    </div>
                    <div class="box1">
                        <el-form-item label="来源发布日期:" required>
                            <el-date-picker
                                v-model="basicForm.sourcePublishDate_"
                                type="date"
                                placeholder="选择日期"
                                size="mini"
                                :disabled="disabled"
                            >
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="来源生效日期:">
                            <el-date-picker v-model="basicForm.sourceEffecDate_" type="date" placeholder="选择日期" size="mini" :disabled="disabled">
                            </el-date-picker>
                        </el-form-item>
                    </div>
                    <div class="box1">
                        <el-form-item label="来源备注:">
                            <el-input v-model="basicForm.sourceRemark_" size="mini" :disabled="disabled"></el-input>
                        </el-form-item>
                        <el-form-item label="来源状态:" required>
                            <el-radio-group v-model="basicForm.sourceStatus_" :disabled="disabled">
                                <el-radio v-for="(value, key) in Dict.sourceStatusPojo" :label="key" :key="key">{{ value }}</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </div>
                    <div :class="{ box4: basicForm.sourceType_ != '3', box1: basicForm.sourceType_ == '3' }">
                        <el-form-item label="条款适用产品:">
                            <el-select
                                v-model="basicForm.suitableFund_"
                                placeholder="请选择"
                                size="mini"
                                :disabled="disabled"
                                v-if="basicForm.sourceType_ == '3'"
                            >
                                <el-option></el-option>
                            </el-select>
                            <el-row v-else>
                                <el-col :span="8">
                                    <el-checkbox v-model="basicForm.publicMoneySource_" :disabled="disabled">公募</el-checkbox>
                                    <span>产品类型</span>
                                    <el-select v-model="basicForm.fundTypePublicSource_" placeholder="请选择" size="mini" :disabled="disabled">
                                    </el-select>
                                </el-col>
                                <el-col :span="8">
                                    <el-checkbox v-model="basicForm.simuSource_" :disabled="disabled">私募</el-checkbox>
                                    <span>产品类型</span>
                                    <el-select v-model="basicForm.fundTypeSimuSource_" placeholder="请选择" size="mini" :disabled="disabled">
                                    </el-select>
                                </el-col>
                                <el-col :span="8">
                                    <el-checkbox v-model="basicForm.zhuanhuSource_" :disabled="disabled">专户</el-checkbox>
                                    <span>产品类型</span>
                                    <el-select v-model="basicForm.fundTypeZhuanhuSource_" placeholder="请选择" size="mini" :disabled="disabled">
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </div>
                    <div class="box1">
                        <el-form-item label="附件:" required>
                            <el-upload
                                :multiple="true"
                                :action="actionUrl"
                                :headers="headerObj"
                                :on-preview="downLoadFileBtn"
                                :with-credentials="true"
                                list-type="text"
                                :before-upload="beforeAvatarUpload"
                                :file-list="fileList1"
                                :on-remove="
                                    (res, file) => {
                                        return uploadFileRemove(res);
                                    }
                                "
                                :on-success="
                                    (res, file, fileList) => {
                                        return uploadFileSuccess(res, file, fileList, '执行标准');
                                    }
                                "
                                :on-error="
                                    (res, file, fileList) => {
                                        return uploadFileError(res, file, fileList, '执行标准');
                                    }
                                "
                            >
                                <el-button icon="el-icon-plus" size="mini" :disabled="disabled">附件</el-button>
                            </el-upload>
                        </el-form-item>
                    </div>
                </div>
            </div>
        </el-form>
    </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { sourceManageDTO } from '../../vo';
import Dict from '../../dict/index';
import { getUser } from '@/utils/user-util';
import { downLoadFile } from '@/utils/request';
@Component({ name: 'SourceManageInfo', components: {} })
export default class SourceManageInfo extends Vue {
    Dict = new Dict();
    private actionUrl = ''; // 附件上传url

    basicForm: sourceManageDTO = {
        sourceType_: '',
        sourceGroupType_: '',
        sourceCode_: '',
        sourceName_: '',
        sourceVisible_: '',
        sourceSuitableFund_: '',
        sourceFile_: '',
        sourceStatus_: '',
        sourcePublishDate_: '',
        sourceEffecDate_: '',
        sourceRemark_: '',
        creator_: '',
        creatDate_: '',
        modifier_: '',
        moduifyDate_: '',
        publicMoneySource_: true,
        fundTypePublicSource_: '',
        simuSource_: true,
        fundTypeSimuSource_: '',
        zhuanhuSource_: true,
        fundTypeZhuanhuSource_: '',
    };
    BASE_URL_API: string;
    headerObj = {
        Authentication: getUser().sessionId,
    };
    fileList1: any[] = [
        // { name: '附件1', url: 'relativePath', fileNo: '21' },
    ];
    get disabled() {
        return this.basicForm['operationType'] == 'look';
    }
    mounted() {
        this.basicForm = JSON.parse(JSON.stringify(this.$attrs.info));
        console.log(this.basicForm, this.Dict.cardStatusPojo, 'basicForm');

        this.actionUrl = this.BASE_URL_API + '/apiAssetFile/upload';
    }

    beforeAvatarUpload(file) {
        // const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 10;

        // if (!isJPG) {
        //     this.$message.error('上传头像图片只能是 JPG 格式!');
        // }
        if (!isLt2M) {
            this.yh_message_warn('上传大小不能超过 10MB!');
        }
        return isLt2M;
    }

    // 文件上传
    uploadFileSuccess(res, file, fileList, type) {
        console.log('文件上传', res);
        if (res.returnMsg && res.returnMsg !== 'SUCCESS') {
            this.$message.warning(res.returnMsg);
            return;
        }
        this.fileList1.push({
            ...res.data,
            name: res.data.fileName,
            url: res.data?.relativePath,
            fileNo: res.data.fileNo,
        });
    }

    // 文件上传报错
    uploadFileError(res, file, fileList, type) {
        this.$message.warning('文件格式不支持!');
    }

    // 下载文件
    downLoadFileBtn(param) {
        downLoadFile({
            url: '/system/download/file/' + param.fileNo,
            method: 'get',
        });
    }

    // 删除已上传文件
    uploadFileRemove(param) {
        this.fileList1.forEach((item, index) => {
            if (item.fileNo == param.fileNo) {
                this.fileList1.splice(index, 1);
            }
        });
    }
}
</script>
<style lang="scss" scoped>
h3 {
    width: 80px;
    height: 30px;
    position: relative;
    top: 18px;
    left: 8px;
    text-align: center;
    background: #fff;
}
.form-box {
    border: 1px dashed #575757;
    padding-right: 5px;
    .box1 {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .box4 {
        .el-row {
            .el-col-8 {
                min-width: 220px;
                padding-right: 10px;
                span {
                    margin: 0 10px;
                }
                /deep/ .el-select {
                    width: calc(100% - 120px);
                }
            }
        }
    }
}

.box5 {
    display: grid;
    grid-template-columns: 1fr 1fr;
}
/deep/ .el-input {
    width: 100%;
}
/deep/ .el-select {
    width: 100%;
}

/deep/ .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label:after {
    color: var(--primary);
}
</style>
